/*
 * @Author: Leo.wang wanglizhigs@163.com
 * @Date: 2023-12-19 22:50:44
 * @LastEditors: Leo.wang wanglizhigs@163.com
 * @LastEditTime: 2023-12-19 22:58:06
 * @FilePath: /tuberculosis_screening_display_system/src/components/transform.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// [
//   {"type":"Feature","properties":{"adcode":330100,"name":"杭州市"}},
//   {"type":"Feature","properties":{"adcode":330100,"name":"杭州市"}},
//   {"type":"Feature","properties":{"adcode":330100,"name":"杭州市"}},
//   {"type":"Feature","properties":{"adcode":330100,"name":"杭州市"}},
//   {"type":"Feature","properties":{"adcode":330100,"name":"杭州市"}},
//   {"type":"Feature","properties":{"adcode":330100,"name":"杭州市"}},
// ]

import fs from 'fs';

// 读取原始 JSON 文件
fs.readFile('shandong.json', 'utf8', (err, data) => {
  if (err) {
    console.error(err);
    return;
  }

  try {
    const jsonData = JSON.parse(data);

    // 遍历 JSON 数组，将adcode复制到name上，将name复制到label上
    jsonData.features = jsonData.features.map(item => {

      const {adcode, name} = item.properties

      return {
        ...item,
        properties: {
          ...item.properties,
          label: name,
          name:adcode,
          
        }
      }
    });

    // 写入新的 JSON 文件
    fs.writeFile('modified_data.json', JSON.stringify(jsonData, null, 2), 'utf8', (err) => {
      if (err) {
        console.error(err);
        return;
      }
      console.log('新的 JSON 文件已生成！');
    });

  } catch (err) {
    console.error('Invalid JSON data:', err);
  }
});
